package com.athuawei.thread;

import java.util.logging.Logger;

public class CurrentThread {
    private static final Logger LOGGER = Logger.getLogger(CurrentThread.class.getName());

    public static void main(String[] args) throws InterruptedException {
        LOGGER.info("在有阻塞状态（sleep/wait/join)" +
                "的while循环中应用interrupt()和isInterrupted()");
        Thread thread = new Thread(() -> {
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    LOGGER.info("线程["
                            + Thread.currentThread().getName() + "]正在运行...");
                    Thread.sleep(5000);
                }
            } catch (InterruptedException e) {
                LOGGER.info("线程[" + Thread.currentThread().getName() + "]停止运行");
                e.printStackTrace();
            }
        });
        thread.start();
        Thread.sleep(200);
        thread.interrupt();
    }
}
